﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class WebUserControl_ControlCatMaTVV : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    static string error = "";
    static DataTable db;
    string str = BCDataCenter.Configuration.CurrentConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getTTPP();
        }
    }
    private void getTTPP()
    {
        dt = new ClassExecute.ClassExecute();
        DataTable TTPP = dt.Get_Data_DataTable(str, ref error, "[GET_SITENAME_ALL]", CommandType.StoredProcedure);
        DropTTPP.DataSource = TTPP;
        DropTTPP.DataValueField = "Sitecode";
        DropTTPP.DataTextField = "sitename";
        DropTTPP.DataBind();

    }
    protected void btSave_Click(object sender, EventArgs e)
    {
        try
        {
            dt = new ClassExecute.ClassExecute();

            CheckBox c;
            string salesp_key = "";
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                c = (CheckBox)GridView1.Rows[i].FindControl("CheckMove");
                if (c.Checked)
                {
                    salesp_key = GridView1.Rows[i].Cells[1].Text.Substring(0,GridView1.Rows[i].Cells[1].Text.IndexOf(Convert.ToChar("_")));
                    dt.ExecuteSQl_bool(str, CommandType.StoredProcedure, "ls_deleteBA", ref error,
                        new SqlParameter("@selSalesPKey", salesp_key));
                }
            }
            BindGrid();

        }
        catch (Exception ex)
        {
            BCDataCenter.ClassWriteLogErr obj = new BCDataCenter.ClassWriteLogErr();
            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            obj.ErrorLog(ex.Message, method);
        }
    }
    protected void btXem_Click(object sender, EventArgs e)
    {
        BindGrid();
    }
    void BindGrid()
    {
        try
        {
            dt = new ClassExecute.ClassExecute();
            db = dt.Get_Data_DataTable(str, ref error, "K_ReportTVVNotWork", CommandType.StoredProcedure,
                new SqlParameter("@username", Session["username"].ToString()),
                new SqlParameter("@Sitecode", DropTTPP.SelectedValue.ToString()),
                new SqlParameter("@thang", 6));
            if (db.Rows.Count > 0)
            {
                GridView1.DataSource = db;
                GridView1.DataBind();
            }
        }
        catch (Exception ex)
        {
            BCDataCenter.ClassWriteLogErr obj = new BCDataCenter.ClassWriteLogErr();
            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            obj.ErrorLog(ex.Message, method);
        }
    }
   
}
